<template>
    <view>
        <view class="txl-step-bar" v-if="stepBar.length>0">
			<view v-for="(item, i) in stepBar" :key="i" :class="item.id ==activeId?'active':''">
				<uni-icons v-if="item.id!=-1" type="right" size="20rpx" :color="item.id ==activeId?'#555':'#02A7F0'"></uni-icons>
				<text :class="['text', {'lastText': item.id == activeId}, {activeText: item.id != activeId}]" @click="preStep(item.id)">{{item.name}}</text>
			</view>
		</view>
        <view v-for="(org, i) in starContact" :key="i">
            <view class="txl-org-item" v-if="org.type" @click="nextStep(org)">
                <radio class="radio" v-if="type==2" :value="org.id+''" :checked="departmentIds.findIndex(item=>item.id == org.id)!=-1"></radio>
                <view class="logo-name">
                    <image class="logo" src="/static/txl/zzjg-icon.png" mode="aspectFill"></image>
                    <text class="name">{{org.name}}<text class="number">({{org.children?org.children.length:org.students.length}}人)</text></text>
                    
                </view>
                <text class="btn" v-if="type==2" @click.stop="nextStep(org, 'btn')">下级</text>
                <uni-icons v-if="type==1" type="right" color="#aaa"></uni-icons>
            </view>
            <view class="txl-org-item" v-else @click="chatPage(org)">
                <radio class="radio" v-if="type==2" :value="org.id+''" :checked="org.userType==2&&studentIds.indexOf(org.id)!=-1 || org.userType==1&&adminIds.indexOf(org.id)!=-1"></radio>
                <view class="logo-name">
                    <image class="logo" :src="utils.headImage(org)" mode="aspectFill"></image>
                    <text class="name">{{org.name}}</text>
                </view>
                <view class="" v-if="org.type==4">
                    <text class="type" v-if="0">校长</text>
                    <uni-icons customPrefix="iconfont" type="icon-icon--" size="40rpx"></uni-icons>
                </view>
            </view>
        </view>
    </view>
</template>
<script>
export default {
    data() {
        return {
            // starContact: []
            activeId: -2
        }  
    },
    props: {
        starContact: {
            type: Array,
            default: ()=>[]
        },
        stepBar: {
            type: Array,
            default: ()=>[]
        },
    },
    mounted() {
		this.infoData()
	},
    methods: {
        infoData(){
            this.stepBar.splice(1);
            let item = {name: '外部联系人', id: -2}
			this.stepBar.push(item)
        },
        preStep(id){
			if(id == -1){
				this.$emit('selectGroup', id)
				return
			}
			if(this.activeId == id) return;
			this.activeId = id;
			let type = this.stepBar.findIndex(item => item.id==id);
			type = type

			this.stepBar.splice(type+1)
			if(type==1){
				
			}else if(type == 2){
				
			}else if(type == 3){
				
			}
		},
        nextStep(info, position){
			if(this.type == 2 && position!='btn'){
                this.radioChange(info.type, info.id);
                return
            }
			this.activeId = info.tableId || info.id;

			
			if(info.type==3){
				
			}
            let item = {name: info.name, id: this.activeId}
			this.stepBar.push(item)

		},
        radioChange(type, id, userType){
            // let index = -1;
            // if(type>0){
            //     index = this.departmentIds.findIndex(item=>item.id == id)
            //     if(index!=-1){
            //         this.departmentIds.splice(index, 1)
            //     }else{
            //         this.departmentIds.push({id: id, stratum: type})
            //     }
                
            // }else if(userType == 2){
            //     index = this.studentIds.indexOf(id);
            //     if(index!=-1){
            //         this.studentIds.splice(index, 1)
            //     }else{
            //         this.studentIds.push(id)
            //     }
                
            // }else if(userType == 1){
            //     index = this.adminIds.indexOf(id);
            //     console.log(this.adminList, index)
            //     if(index!=-1){
            //         this.adminIds.splice(index, 1)
            //     }else{
            //         this.adminIds.push(id)
            //     }
            // }
            // let obj = {
            //     department: this.departmentIds,
            //     student: this.studentIds,
            //     admin: this.adminIds
            // }
            // this.$emit('selectIds', obj)
        },
    }
}
</script>
<style lang="scss" scoped>

</style>